package com.iretailer.report.web.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iretailer.report.base.BaseAction;
import com.iretailer.report.dto.ReRemoteServers;
import com.iretailer.report.model.RemoteServers;
import com.iretailer.report.util.RMap;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Auther: xjw
 * @Date: 2019/1/28 10:27
 * @Description:
 */
@RestController
public class ServerController extends BaseAction {


    private Map<String, Object> grid() {
        List<RemoteServers> all = remoteServicesService.list(null);
        return RMap.ok(all);
    }

    private Map<String, Object> select(String serverType) {
        List<RemoteServers> result = remoteServicesService.list(new QueryWrapper<RemoteServers>().lambda().eq(RemoteServers::getServerType, serverType));
        return RMap.ok(result);
    }

    public Map<String, Object> save(ReRemoteServers re) {
//        ModelMapper modelMapper = new ModelMapper();
        RemoteServers rs = modelMapper.map(re, RemoteServers.class);
        boolean result = remoteServicesService.saveOrUpdate(rs);
        if (result) {
            return RMap.ok();
        } else {
            return RMap.error();
        }
    }

    private Map<String, Object> del(Long id) {
        boolean result = remoteServicesService.removeById(id);
        if (result) {
            return RMap.ok();
        } else {
            return RMap.error();
        }
    }
}
